@extends('layouts.app')

@section('title', $user->nicename.'-用户详情')

@section('content-fluid')

<div class="panel panel-profile">
	<div class="clearfix">
		<!-- LEFT COLUMN -->
		<div class="profile-left">
			<!-- PROFILE HEADER -->
			<div class="profile-header">
				<div class="overlay"></div>
				<div class="profile-main" style="padding: 55px;background-image: url('{{config('app.inlet_src')}}assets/img/profile-bg1.png');">
					@if(empty($user->pic))
					<img src="{{config('app.inlet_src')}}assets/img/user{{rand(1,4)}}.png" class="img-circle" alt="{{$user->nicename}}" style="width: 100px;height: 100px;">
					@else
					<img src="{{$user->avatar}}" class="img-circle" alt="{{$user->nicename}}" style="width: 100px;height: 100px;">
					@endif
					<h3 class="name">{{$user->nicename}}</h3>
					<!-- <span class="online-status status-available">炒饼</span> -->
				</div>
				<div class="profile-stat">
					<div class="row">
						<div class="col-md-4 stat-item">
							{{$orders->total()}} <span>下单次数</span>
						</div>
						<div class="col-md-4 stat-item">
							￥{{$user->account}} <span>账户余额</span>
						</div>
						<div class="col-md-4 stat-item">
							{{$user->integral}} <span>积分余额</span>
						</div>
					</div>
				</div>
			</div>
			<!-- END PROFILE HEADER -->
			<!-- PROFILE DETAIL -->
			<div class="profile-detail">
				<div class="profile-info">
					<h4 class="heading">个人信息</h4>
					<ul class="list-unstyled list-justify">
						<li>注册时间 <span>{{$user->insert_time}}</span></li>
						<li>手机号码 <span>{{$user->tel}}</span></li>
						<li>最后一次登陆时间 <span>{{date('Y-m-d H:i:s',$user->login_time)}}</span></li>
						@if(isset($shop))
						<li>TA的餐饮商铺 <span><a href="/shopDetails?shopid={{$shop->shop_id}}">{{$shop->shop_name ?? '未填写'}}</a></span></li>
						@endif
					</ul>
				</div>
				<div class="text-center">
					<a href="javascript:void(0);" class="btn btn-primary suspend-business">更改头像</a>
					&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
					<a href="#" class="btn btn-danger">修改密码</a>
				</div>
			</div>
			<!-- END PROFILE DETAIL -->
		</div>
		<!-- END LEFT COLUMN -->
		<!-- RIGHT COLUMN -->
		<div class="profile-right" style="min-height: 635px;">
			<!-- TABBED CONTENT -->
			<div class="custom-tabs-line tabs-line-bottom left-aligned">
				<ul class="nav" role="tablist">
					<li><a href="#tab-bottom-left1" role="tab" data-toggle="tab" tabindex="0">购卡记录</a></li>
					<li><a href="#tab-bottom-left2" role="tab" data-toggle="tab" tabindex="1">下单记录</a></li>
				</ul>
			</div>
			<div class="tab-content" style="min-height: 300px;">
				<div class="tab-pane fade" id="tab-bottom-left1">
					<div class="table-responsive">
						@if($cards->count()>0)
						<table class="table table-hover">
							<thead>
								<tr>
									<th>卡编号</th>
									<th>套餐</th>
									<th>剩余次数</th>
									<th>购卡时间</th>
								</tr>
							</thead>
							<tbody>
								@foreach($cards as $k=>$v)
								<tr>
									<td>{{$v->card_identi}}</td>
									<td>
										{{$v->card_name}}
									</td>
									@if(session('power')=='*')
									<td><input type="number" name="card_number" value="{{$v->card_num}}" data-cardid="{{$v->card_identi}}">({{$v->card_num}})</td>
									@else
									<td>{{$v->card_num}}</td>
									@endif
									<td>{{date('Y-m-d H:i',$v->insert_time)}}</td>
								</tr>
								@endforeach
							</tbody>
						</table>
						{{ $cards->appends(['userid' => $user->user_id])->fragment('tab-bottom-left1')->links() }}
						@else
						<h3>暂无购卡记录</h3>
						@endif
				    </div>
				</div>
				<input type="hidden" name="shop_id" value="{{$user->user_id}}">
				<div class="tab-pane fade" id="tab-bottom-left2">
					<div class="table-responsive">
						@if($orders->count()>0)
						<table class="table table-hover">
							<thead>
								<tr>
									<th>订单号</th>
									<th>流水号</th>
									<th>隶属商铺</th>
									<th>下单时间</th>
									<th>下单餐品</th>
									<th>消费金额</th>
									<th>订单状态</th>
								</tr>
							</thead>
							<tbody>
								@foreach($orders as $k=>$v)
								<tr>
									<td>{{$v->order_number}}</td>
									<td>{{$v->order_sernum}}</td>
									<td>
										@if(session('region') == 1)
										<a href="/shopDetails?shopid={{$v->shops_id}}">{{$v->shop_name}}</a>
										@else
										{{$v->shop_name}}
										@endif
									</td>
									<td>{{$v->insert_time}}</td>
									<td>{{$v->cateslist}}</td>
									<td>{{$v->meal_order_price}}</td>
									<td>{{$order_status[$v->order_status]}}</td>
								</tr>
								@endforeach
							</tbody>
						</table>
						{{ $orders->appends(['userid' => $user->user_id])->fragment('tab-bottom-left2')->links() }}
						@else
						<h3>暂无下单记录</h3>
						@endif
					</div>
				</div>
			</div>
			<!-- END TABBED CONTENT -->
		</div>
		<!-- END RIGHT COLUMN -->
	</div>
</div>

@endsection

@section('js-write')
<script type="text/javascript">
	var m = location.hash;
	$('a[href="'+m+'"]').tab('show');
	$('input[name="card_number"]').change(function(e){
		$.ajaxSetup({
		    headers: {
		        'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
		    }
		});
		$.post('/card/addOne',{'card_id':$(this).attr('data-cardid'),'card_number':$(this).val()},function(response){
			if(response.success){
				toastr.success(response.message);
			}else{
				toastr.error(response.message);
			}
		},'json');
	});
</script>
@endsection